package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.WitnessListInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by windo on 17/1/4.
 */

public class JianzhengrenListTask extends CouponHttpBaseTask{
    private String desireId;
    public JianzhengrenListTask(String desireid) {
        super();
        desireId = desireid;
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject res_json = response.getBody();
        List<WitnessListInfo> list = new ArrayList<>();
        if (res_json != null){
            String res_data = res_json.getString("data");
            list = JSON.parseArray(res_data, WitnessListInfo.class);
        }

        notifyTaskCompleted(TaskResultCode.SUCCESS,list);

    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT){
            CouponHttpRequest request = new CouponHttpRequest();
            request.setApiNo(ApiNo.JIANZHENGREN_LIST);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("desireId",desireId);
            request.setData(jsonObject.toString());
            addRequest(request);
        }
    }
}
